package com.ax.base.common.dao;

import com.ax.base.common.domain.BaseChargeRules;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Repository
public interface BaseChargeRulesMapper {
    /**
     * 药店充值规则*添加新的规则
     *
     * @param baseChargeRules
     * @return
     */
    @Insert("<script>"+
            "insert into base_charge_rules (Charge_Rules_ID, Charge_Months, Give_Days,"+
            "Price, Remarks, Registrar_ID,Registrar_Name,"+
            "create_date, update_date, Flag"+
            ")"+
            "values (#{chargeRulesId}, #{chargeMonths}, #{giveDays},"+
            "#{price}, #{remarks}, #{registrarId},#{registrarName},"+
            "NOW(), #{updateDate}, 1"+
            ")"+
            "</script>")
    int insert(BaseChargeRules baseChargeRules);

    /**
     * 药店充值规则*更改规则
     * @param baseChargeRules
     * @return
     */
    @Update("<script>"+
            "update base_charge_rules"+
            "<set>"+
            "<if test=\"chargeRulesId != null\">"+ " Charge_Rules_ID= #{chargeRulesId}," + "</if>" +
            "<if test=\"chargeMonths != null\">"+ "Charge_Months = #{chargeMonths}," + "</if>" +
            "<if test=\"giveDays != null\">"+ "Give_Days = #{giveDays}," + "</if>" +
            "<if test=\"price != null\">"+ "Price = #{price}," + "</if>" +
            "<if test=\"remarks != null\">"+ "Remarks = #{remarks}," + "</if>" +
            "<if test=\"registrarId != null\">"+ "Registrar_ID = #{registrarId}," + "</if>" +
            "<if test=\"registrarName != null\">"+ "Registrar_Name = #{registrarName}," + "</if>" +
            "<if test=\"createDate != null\">"+ "create_date = #{createDate}," + "</if>" +
            "update_date = NOW(),"+
            "<if test=\"flag != null\">"+ "Flag = #{flag}," + "</if>" +
            "</set>"+
            "<where>"+
             "Charge_Rules_ID = #{chargeRulesId}"  +
            "</where>"+
            "</script>" )
    int update(BaseChargeRules baseChargeRules);

    /**
     * 药店充值规则*查询单个规则
     * @param baseChargeRules
     * @return
     */
    @Select("<script>"+
            "select "+
            "Charge_Rules_ID , Charge_Months, Give_Days , Price, Remarks , Registrar_ID,Registrar_Name,"+
            "create_date, update_date, Flag "+
            "from base_charge_rules"+
            "<where>" +
             " Charge_Rules_ID = #{chargeRulesId} " +
            "<if test=\"flag!=null\">"+"and Flag=#{flag}"+"</if>"+
            "</where>"+
            "</script>")
    BaseChargeRules query(BaseChargeRules baseChargeRules);

    /**
     * 药店充值规则*查询所有的规则
     * @param baseChargeRules
     * @return
     */
    @Select("<script>"+
            "select "+
            "Charge_Rules_ID , Charge_Months, Give_Days , Price, Remarks , Registrar_ID,Registrar_Name,"+
            "create_date, update_date, Flag "+
            "from base_charge_rules"+
            "<where>" +
            "<if test=\"flag!=null\">"+"and Flag=#{flag}"+"</if>"+
            "<if test=\"remarks != null\">"+"and Remarks like \"%\"#{remarks}\"%\" "+ "</if>" +
            "</where>"+
            /*"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+*/
            "</script>")
    List<BaseChargeRules> queryList(Map<String,Object> map);

    
    @Select("<script>"+
            "select count(0) "+
            "from base_charge_rules"+
            "<where>" +
            "<if test=\"flag!=null\">"+"and Flag=#{flag}"+"</if>"+
            "</where>"+
            "</script>")
    Integer count(Map<String,Object> map);
    /**
     * 药店充值规则*删除规则
     * @param chargeRulesId
     * @param flag
     * @return
     */
    @Update("<script>"+
            "update base_charge_rules"+
            "<set>"+
            "update_date = NOW(),"+
            "Flag = #{flag}," +
            "</set>"+
            "<where>"+
            "Charge_Rules_ID in "  +
            "<foreach collection=\"chargeRulesId\" item=\"item\" index=\"index\" open=\"(\" separator=\",\" close=\")\">"+
            "#{item}"+
            "</foreach>"+
            "</where>"+
            "</script>" )
    int delete(ArrayList<Long> chargeRulesId,Integer flag);
}
